package com.itheima.demo3.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

/**
 * Spring Security配置
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig {
    
    /**
     * 配置HTTP安全
     * 临时禁用认证以便测试API
     */
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .anyRequest().permitAll()  // 允许所有请求
            )
            .csrf(AbstractHttpConfigurer::disable)  // 禁用CSRF
            .httpBasic(AbstractHttpConfigurer::disable)  // 禁用HTTP Basic认证
            .formLogin(AbstractHttpConfigurer::disable)  // 禁用表单登录
            .logout(AbstractHttpConfigurer::disable);  // 禁用登出
        
        return http.build();
    }
} 